package jmine.tec.persist.naturalkey;

/**
 * Converter padrão para natural key, passa o objeto para string.
 * 
 * @author lundberg
 */
public class LongNaturalKeyConverter implements NaturalKeyConverter<Long> {

    /**
     * {@inheritDoc}
     */
    public Long convert(Object naturalKey) throws InvalidNaturalKeyException {
        try {
            return naturalKey == null ? null : Long.valueOf(naturalKey.toString());
        } catch (NumberFormatException e) {
            throw new InvalidNaturalKeyException(naturalKey, Long.class);
        }
    }

    /**
     * {@inheritDoc}
     */
    public Class<Long> getTargetClass() {
        return Long.class;
    }
}
